﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GuiLabs.Undo;
using Gizmox.WebGUI.Forms;
using System.Drawing;

namespace Bronze.ReportBuilder.Actions
{
    public class ResizeAction : AbstractAction
    {
        private readonly Control _control;
        private readonly Size newSize;
        private Size _oldSize;
        private bool _needSetValue = true;

        public ResizeAction(Control control,Size newSize)
        {
            this._control = control;
            this.newSize = newSize;
        }

        protected override void ExecuteCore()
        {
            if (!_needSetValue) return;
            _oldSize = _control.Size;
            _control.Size = newSize;

            var designer = _control.Parent as IResizeHost;
            if (designer != null)
            {
                designer.SelectControl(_control, true);
            }
            _needSetValue = true;
        }

        protected override void UnExecuteCore()
        {
            _control.Size = _oldSize;
            var parent = _control.Parent as IResizeHost;
            if (parent != null)
            {
                parent.SelectControl(_control, true);
            }
            _needSetValue = true;
        }


    }

    public class LocationAction : AbstractAction
    {
        private readonly Control _control;
        private readonly Point _location;
        private Point _oldlocation;

        private bool _needSetValue = true;

        public LocationAction(Control control, Point location)
        {
            this._control = control;
            this._location = location;
        }

        protected override void ExecuteCore()
        {
            if (!_needSetValue) return;
            _oldlocation = _control.Location;
            _control.Location = _location;
            var parent = _control.Parent as FormDesigner;
            if (parent != null)
            {
                parent.SelectControl(_control, true);
            }
            _needSetValue = true;
        }

        protected override void UnExecuteCore()
        {
            _control.Location = _oldlocation;
            var parent = _control.Parent as FormDesigner;
            if (parent != null)
            {
                parent.SelectControl(_control, true);
            }
            _needSetValue = true;
        }
    }
}